package com.xbjtech.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xbjtech.mapper.UserMapper;
import com.xbjtech.model.User;
import com.xbjtech.model.UserExample;
import com.xbjtech.model.UserExample.Criteria;
import com.xbjtech.service.UserService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
	
	@Autowired
	UserMapper userMapper;
	
	public void login(String username, String password) throws Exception {
		log.info("username:{},password:{}", username, password);
		log.info("userMapper:{}", userMapper);
	}

	public User selectUserByUsername(String username) {
		UserExample example = new UserExample();
		Criteria criteria = example.createCriteria();
		criteria.andUsernameEqualTo(username);
		List<User> users = userMapper.selectByExample(example);
		if (users != null && users.size() > 0) {
			return users.get(0);
		}
		return null;
	}

	public User selectUserByMobile(String mobile) {
		UserExample example = new UserExample();
		Criteria criteria = example.createCriteria();
		criteria.andMobileEqualTo(mobile);
		List<User> users = userMapper.selectByExample(example);
		if (users != null && users.size() > 0) {
			return users.get(0);
		}
		return null;
	}

}
